package com.zone.demo.domain.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zone.demo.dto.Account;
import com.zone.demo.dto.User;
import org.apache.ibatis.annotations.Select;

/**
 * Created with IntelliJ IDEA.
 * User: SJP
 * Date: 2021/7/8
 * Time: 14:04
 * Description: No Description
 * @author sjp
 */
public interface UserMapper extends BaseMapper<User> {

    /**
    * Description 通过用户名字获取账户信息
    * @author shao
    * @param name:
    * @date 2021/7/8 18:35
    * @return com.zone.demo.dto.Account
    */
    @Select("SELECT amount FROM account Left JOIN user ON user.acid  = account.account_id where user.name = #{name}")
    Account getAmountByName(String name);
    /**
    * Description 创建user表单
    * @author shao
    * @param :
    * @date 2021/7/8 18:35
    * @return void
    */
    @Select("CREATE TABLE IF NOT EXISTS `user`(\n" +
            "     uid 		 INT(12)      COMMENT \"序号\",\n" +
            "     name		 VARCHAR(10)  COMMENT \"名字\",\n" +
            "     sex 		 CHAR         COMMENT\"性别 M for male F for female\",\n" +
            "     acid       INT(9)      COMMENT\"账号id\",\n" +
            "     gmt_create DATETIME     COMMENT\"创建时间\",\n"+
            "     gmt_modified DATETIME COMMENT\"更新时间\", \n"+
            "     PRIMARY KEY (`uid`)\n" +
                    ")ENGINE=InnoDB DEFAULT CHARSET=utf8;\n")
    void createTableUser();

    /**
    * Description 创建账户表单
    * @author shao
    * @param :
    * @date 2021/7/8 18:36
    * @return void
    */
    @Select("CREATE TABLE IF NOT EXISTS `account`(\n" +
            "    `account_id`    INT(9)   COMMENT \"账号\",\n" +
            "    `amount`        INT(20)  COMMENT \"账户余额\",\n" +
            "    `phone_number`  INT(11)  COMMENT \"预留手机\",\n" +
            "    `gmt_create`    DATETIME COMMENT \"创建时间\",\n" +
            "    `gmt_modified`  DATETIME COMMENT \"更新时间\"\n" +
            "     PRIMARY KEY (`account_id`)\n" +
            ")ENGINE=InnoDB DEFAULT CHARSET=utf8;\n")
    void createTableAccount();

    /**
    * Description 添加记录到user
    * @author shao
    * @param id:
    * @param name:
    * @param sex:
    * @param acid:
    * @param gmtCreat:
    * @param gmtModified:
    * @date 2021/7/8 18:36
    * @return void
    */
    @Select("insert into user(id,name,sex,acid,gmtCreat,gmtModified) values(#{id},#{name},#{sex},#{acid},#{gmtCreat},#{gmtModified})")
    void insertDataToUser(Integer id,String name,String sex,Integer acid ,String gmtCreat,String gmtModified);


    /**
    * Description 添加记录到account
    * @author shao
    * @param accountId:
    * @param amount:
    * @param phoneNumber:
    * @param gmtCreat:
    * @param gmtModified:
    * @date 2021/7/8 18:36
    * @return void
    */
    @Select("insert into account(account_id,amount,phone_number,class,gmt_create,gmtCreat,gmtModified) values(#{accountId},#{amount},#{phoneNumber},#{gmtCreat},#{gmtModified})")
    void insertDataToAccount(Integer accountId,Integer amount ,String phoneNumber,String gmtCreat,String gmtModified);

}
